package cn.school.workmgr.service.impl;

import cn.school.common.api.CommonPage;
import cn.school.common.utils.StringUtils;
import cn.school.common.utils.SysUserUtils;
import cn.school.notice.entity.FamilyNotice;
import cn.school.workmgr.dao.RecruitEnrollDao;
import cn.school.workmgr.dao.RecruitEnrollEntityDao;
import cn.school.workmgr.entity.RecruitEnroll;
import cn.school.workmgr.entity.RecruitEnrollEntity;
import cn.school.workmgr.service.RecruitEnrollService;
import cn.school.workmgr.vo.RecruitEnrollVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class RecruitEnrollServiceImpl extends ServiceImpl<RecruitEnrollDao, RecruitEnroll> implements RecruitEnrollService {
    @Resource
    private RecruitEnrollDao recruitEnrollDao;
    
    @Resource
    private RecruitEnrollEntityDao recruitEnrollEntityDao;
    
    @Override
    public CommonPage<RecruitEnroll> pageList(RecruitEnrollVO vo) {
        IPage<RecruitEnroll> ipage = new Page<>();
        ipage.setCurrent(vo.getPageNum());
        ipage.setSize(vo.getPageSize());
        LambdaQueryWrapper<RecruitEnroll> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(RecruitEnroll::getTenantId, SysUserUtils.getSysUser().getTenantId());
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(vo.getEnrollName()), RecruitEnroll::getEnrollName, vo.getEnrollName());
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(vo.getMajorName()), RecruitEnroll::getMajorName, vo.getMajorName());
        IPage<RecruitEnroll> enrollIPage = recruitEnrollDao.selectPage(ipage, lambdaQueryWrapper);
        return CommonPage.restPage(enrollIPage);
        
    }

    @Override
    public int saveRecruitEnroll(RecruitEnrollEntity vo) {
        vo.setCreateTime(new Date());
        vo.setTenantId(vo.getTenantId());
        return recruitEnrollEntityDao.insert(vo);
    }
}
